<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <script type="text/javascript" src="/js/jquery-3.5.1.min.js"></script>
    <script type="text/javascript" src="/layer/layer.js"></script>
    <script>
        $(function () {
            getResumes();
        })

        function getResumes() {
            $.ajax({
                url: "http://localhost:8080/resume/getAll",
                method: "get",
                success: function (data) {
                    let resumes = data.result
                    let tbody = "";
                    $.each(resumes, function (n, value) {
                        let trs = "";
                        trs += "<tr><td>" + value.name + "</td><td>" + value.address + "</td><td>" + value.phone +
                            "</td><td><input type='button' value='编辑' onclick='toEditResume(" + value.id + ")'/>" +
                            "<input type='button' value='删除' onclick='deleteResume(" + value.id + ")'/></td></tr>";
                        tbody += trs;
                    });
                    $("#dataTable").append($(tbody))
                }
            });
        }

        function addResume() {
            $(location).attr('href', 'http://localhost:8080/resume/toAdd/')
        }

        function toEditResume(id) {
            $(location).attr('href', 'http://localhost:8080/resume/toUpdate/' + id)
        }

        function deleteResume(id) {
            layer.confirm('确定删除吗？', {
                btn: ['删除', '取消']
            }, function () {
                $.ajax({
                    url: "http://localhost:8080/resume/delete/" + id,
                    method: "get",
                    success: function (data) {
                        let code = data.code
                        if (code === 0) {
                            layer.msg('删除成功');
                            window.location.reload();
                        } else {
                            layer.msg(data.message);
                        }
                    }
                })
                layer.close()
            }, function () {
                layer.close()
            });
        }
    </script>
    <title></title>
</head>
<body>
<table border="1" id="dataTable">
    <thead>
    <tr>
        <td colspan="3" align="center">简历列表</td>
        <td><input type="button" onclick="addResume()" value="添加用户"></td>
    </tr>
    <tr>
        <td>名称</td>
        <td>地址</td>
        <td>手机号</td>
        <td>操作</td>
    </tr>
    </thead>
</table>
</body>
</html>
